package com.netty.task;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import com.netty.exception.NoTaskException;

public enum TaskManager {
	INSTANCE;
	BlockingQueue<Task> taskes = new LinkedBlockingQueue<Task>();
	
	public Task getTask() throws InterruptedException, NoTaskException {
		Task task =  taskes.poll(5, TimeUnit.SECONDS);
		if (task == null) {
			throw new NoTaskException();
		}
		return task;
	}
	
	public void addTask(Task task) throws InterruptedException {
		//taskes.pu
		taskes.put(task);
	}
}
